/*

 * Copyright (C) 2021 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */
package com.cardinalsolutions.progressindicator.slice;

import com.cardinalsolutions.circleprogressindicator.CircleProgressIndicator;
import com.cardinalsolutions.progressindicator.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
import ohos.agp.components.Slider;
import ohos.agp.utils.Color;

/**
 * MainAbilitySlice
 *
 * @since : 2021.5.24
 */
public class MainAbilitySlice extends AbilitySlice {
    private CircleProgressIndicator circleProgressIndicator;
    private Text myText;
    private Slider slider;

    @Override
    public void onStart(Intent intent) {
        getWindow().setStatusBarColor(Color.getIntColor("#2D3B9C"));
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        if (findComponentById(ResourceTable.Id_demo_mpc) instanceof CircleProgressIndicator) {
            circleProgressIndicator =
                (CircleProgressIndicator) findComponentById(ResourceTable.Id_demo_mpc);
        }
        if (findComponentById(ResourceTable.Id_compliance_percentage) instanceof Text) {
            myText = (Text) findComponentById(ResourceTable.Id_compliance_percentage);
        }
        if (findComponentById(ResourceTable.Id_seek_bar) instanceof Slider) {
            slider = (Slider) findComponentById(ResourceTable.Id_seek_bar);
        }
        myText.setText("0%");
        slider.setValueChangedListener(new Slider.ValueChangedListener() {
            @Override
            public void onProgressUpdated(Slider slider, int i1, boolean b1) {
                circleProgressIndicator.setPercent((float) (i1*0.01));
                myText.setText(i1 + "%");
            }

            @Override
            public void onTouchStart(Slider slider) {
            }

            @Override
            public void onTouchEnd(Slider slider) {
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
